package com.Nuyoah.demo01.DTO.common;


import lombok.Getter;

import java.io.Serializable;

/**
 * 分页查询公共参数
 */
public class BasePageReq implements Serializable {
    /**
     * 默认字段排序方式-不传默认DESC
     * 升序-ASC
     * 降序-DESC
     */
    private String sort = "DESC";

    /**
     * 页码
     */
    private Integer pageNum = 1;

    /**
     * 每页条数 默认10
     */
    private Integer pageSize = 10;

    /**
     *  社区名称,默认为空（查询所有社区下的帖子）
     */
    private String communityName = "";

    /**
     *Tips
     */
    // TODO 目前仅提供了全部查询和根据社区名称查询，后续根据前端所需功能进行完善

    public BasePageReq() {
    }

    public BasePageReq(Integer pageSize, Integer pageNum) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public BasePageReq(Integer pageSize, Integer pageNum, String communityName) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.communityName = communityName;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }
    // 计算 offset
    public Integer getOffset() {
        if (pageNum != null && pageSize != null) {
            return (pageNum - 1) * pageSize;
        }
        return 0;
    }

    public String getCommunityName() {
        return communityName;
    }

    public void setCommunityName(String communityName) {
        this.communityName = communityName;
    }
}
